package com.binarysoft.service.obj;

import java.util.ArrayList;
import java.util.Collection;

public class UnitTest {

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) {
		Collection<TestObj> c1 = new ArrayList<TestObj>();
		Collection<TestObj> c2 = new ArrayList<TestObj>();

		TestObj t1 = new TestObj(1, "1", "name1", "value1");
		TestObj t2 = new TestObj(2, "2", "name2", "value2");
		TestObj t3 = new TestObj(3, "3", "name3", "value3");
		c1.add(t1);
		c1.add(t2);
		c1.add(t3);

		TestObj t11 = new TestObj(1, "1", "name11", "value11");
		TestObj t22 = new TestObj(2, "2", "name22", "value22");
		TestObj t33 = new TestObj(3, "3", "name33", "value33");
		c2.add(t11);
		c2.add(t22);
		c2.add(t33);

		boolean rs1 = c1.containsAll(c2);
		System.out.println(rs1);
		c1.removeAll(c2);
		System.out.println("c1.size=" + c1.size());
		c1.addAll(c2);
		System.out.println("c1.size=" + c1.size());

		for (TestObj obj : c2) {
			System.out.println(obj);
		}

	}

	private static class TestObj {
		private long id;
		private String key;
		private String name;
		private String value;

		public TestObj(long id, String key, String name, String value) {
			super();
			this.id = id;
			this.key = key;
			this.name = name;
			this.value = value;
		}

		public long getId() {
			return id;
		}

		public void setId(long id) {
			this.id = id;
		}

		public String getKey() {
			return key;
		}

		public void setKey(String key) {
			this.key = key;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getValue() {
			return value;
		}

		public void setValue(String value) {
			this.value = value;
		}

		@Override
		public int hashCode() {
			StringBuffer sb = new StringBuffer();
			sb.append(this.id).append("-").append(this.key);
			return sb.hashCode();
		}

		@Override
		public String toString() {
			return "TestObj [id=" + id + ", key=" + key + ", name=" + name + ", value=" + value + "]";
		}

		@Override
		public boolean equals(Object obj) {
			boolean c1 = (obj instanceof TestObj);
			TestObj p = (TestObj) obj;
			boolean c2 = p.id == this.id;
			boolean c3 = p.key.equalsIgnoreCase(this.key);
			return c1 && c2 && c3;
		}
	}
}
